/**********************************************************************************
 * Code license:  GNU General Public License v3                                   *
 * Main page:     https://code.google.com/p/library-cross-platform/               *
 * Issue tracker: https://code.google.com/p/library-cross-platform/issues/list    *
***********************************************************************************/

package library.ui;

import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
public class ElementContainer extends Element {

  protected List    container      = new ArrayList();
  protected int     char_count_max = 10;
  protected boolean isShowBorder   = true;
  
  protected ElementContainer(int element_type) {
    super(element_type);
  }
  
  public ElementContainer() {
    super(ELEMENT_CONTAINER_TYPE);
  }
  
  public ElementContainer(String name) {
   this(ELEMENT_CONTAINER_TYPE);
   this.setName(name);
  }
  
  public void add(int index, Element element) {
    container.add(index, element);
  }
	  
  public void add(Element element) {
    container.add(element);
  }

  public Element get(int index) {
    return (Element)container.get(index);
  }
  
  public void remove(int index) {
    container.remove(index);
  }
  
  public Element getByID(long id) {
   Iterator it      = container.iterator();
   Element  element = null;
   while(it.hasNext()) {
    element = (Element)it.next();
    if(element.getElementType() == ELEMENT_CONTAINER_TYPE     ||
       element.getElementType() == RADIOBUTTON_CONTAINER_TYPE ||
       element.getElementType() == TAB_CONTAINER_TYPE) {
         element = ((ElementContainer)element).getByID(id);
    }

    if(element.getElementID() == id)
     break;
   }
   return element;
  }
  
  public int size() {
    return container.size();
  }
  
  public void setTitleSize(int size) {
    char_count_max = size;
  }
  
  public int getTitleSize() {
    return char_count_max;
  }
  
  public void showBorder(boolean b) {
    isShowBorder = b;
  }
  
  public boolean isShowBorder() {
    return isShowBorder;
  }
}
